package com.pml.dao.proxy;

import com.pml.dao.IEmpDAO;
import com.pml.dao.impl.EmpDAOImpl;
import com.pml.dbc.DatabaseConnection;
import com.pml.vo.Emp;

import java.util.List;

public class EmpDAOProxy implements IEmpDAO{
    private DatabaseConnection databaseConnection;
    private IEmpDAO iEmpDAO;
    public EmpDAOProxy() throws Exception{
        this.databaseConnection=new DatabaseConnection();
        this.iEmpDAO=new EmpDAOImpl(this.databaseConnection.getConnection());
    }

    public boolean doCreate(Emp emp) throws Exception{
        boolean flag=false;
        try{
            if (this.iEmpDAO.findById(emp.getEmpno())==null) {
                flag = this.iEmpDAO.doCreate(emp);
                System.out.println(flag);
            }
        }catch (Exception e){
            throw e;
        }finally {
            this.databaseConnection.close();
        }
        return flag;
    }
    public List<Emp> findAll(String keyword) throws Exception{
        List<Emp> empList=null;
        try{
            empList=this.iEmpDAO.findAll(keyword);
        }catch (Exception e){
            throw e;
        }finally {
            this.databaseConnection.close();
        }
        return empList;
    }
    public Emp findById(int empno) throws Exception{
        Emp emp=null;
        try{
            emp=this.iEmpDAO.findById(empno);
        }catch (Exception e){
            throw e;
        }finally {
            this.databaseConnection.close();
        }
        return emp;
    }


}
